﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class EditSSLSComPersonControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        CustomGridView CustomGridList1;
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            CustomGridList1 = (CustomGridView)FindControl("CustomGridList1");
            if (!base.Page.IsPostBack)
            {
                Bind();
            }
            CustomGridList1.OnLoadData += new EventHandler(CustomGridList1_OnLoadData);
            CustomGridList1.RowDeleting += new GridViewDeleteEventHandler(CustomGridList1_RowDeleting);
            Button btnsearch = (Button)FindControl("btnsearch");
            btnsearch.Click += new EventHandler(Go_Search);
        }


        protected void Go_Search(object sender, EventArgs e)
        {
            Bind();
        }
        protected void Bind()
        {
            string cid = base.Page.Request["CID"];
            DataTable dt = _EluZSDataProvider.GetSSComPer("临时实施工作人员", cid, GetSqlWhere());
            CustomGridList1.DataSource = dt;
            CustomGridList1.RecordCount = dt.Rows.Count;
            CustomGridList1.PageSize = 10;
            CustomGridList1.DataKeyNames = new string[] { "ID" };
            CustomGridList1.DataBind();
        }
        protected void CustomGridList1_OnLoadData(object sender, EventArgs e)
        {
            Bind();
        }
        protected void CustomGridList1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string strid = CustomGridList1.DataKeys[e.RowIndex].Value.ToString();
            bool del = _EluZSDataProvider.DeleteXmByID("ZS_PGJGRY", "id", strid);
            if (del)
            {
                Bind();
                Antu.Utilities.UtilitiesPage.AlertDialog("删除成功！", "");
            }
        }
        protected string GetSqlWhere()
        {
            string sqlWhere = string.Empty;
            TextBox rymc = (TextBox)FindControl("rymc");
            if (!string.IsNullOrEmpty(rymc.Text))
            {
                sqlWhere += " and name like '%" + rymc.Text.Trim() + "%'";
            }
            return sqlWhere;
        }
    }
}


